﻿/// <reference path="../../vendor/angular/angular.min.js" />
/// <reference path="../../vendor/angular/angular-route.min.js" />
/// <reference path="../../vendor/angular/angular-resource.min.js" />
/// <reference path="../../vendor/angular/angular-mocks.js" />
/// <reference path="../../src/folders/folderController.js" />
/// <reference path="../../src/folders/folderResource.js" />
/// <reference path="../../src/folders/expandableFolderController.js" />

describe('should test folder controller', function () {
	var $httpBeckend, $scope, Folders, folderController;

	beforeEach(module('src.folders.foldersResource'));
	beforeEach(module('src.folders.folderController'));
	beforeEach(module('src.folders.expandableFolderController'));

	beforeEach(inject(function (_$httpBackend_, $rootScope, $controller, _Folders_) {
		$httpBeckend = _$httpBackend_;
		$scope = $rootScope.$new();
		Folders = _Folders_;

		$httpBeckend.expectGET('api/folder').respond([
			{ FolderId: 1, ParentFolderId: null, UserId: 1, Name: 'Incomming', NumberOfUnreadedEmails: 1, ChildFolders: [] },
			{ FolderId: 2, ParentFolderId: 1, UserId: 1, Name: 'Incomming from haven', NumberOfUnreadedEmails: 1, ChildFolders: [] },
			{ FolderId: 3, ParentFolderId: null, UserId: 1, Name: 'Sent', NumberOfUnreadedEmails: 1, ChildFolders: [] },
			{ FolderId: 4, ParentFolderId: null, UserId: 1, Name: 'Spam', NumberOfUnreadedEmails: 1, ChildFolders: [] }
		]);

		folderController = $controller('FolderController', {
			$scope: $scope,
			Folders: Folders
		});
	}));

	it('First folder should have one child folder', function () {
		$httpBeckend.flush();

		expect($scope.folders[0].ChildFolders.length).toBe(1);
		expect($scope.folders[0].ChildFolders[0].Name).toBe('Incomming from haven');
	});

	it('There should be three top level folders', function () {
		$httpBeckend.flush();
		expect(numberOfTopLevelFolders()).toBe(3);
	});

	function numberOfTopLevelFolders() {
		return $scope.folders.length;
	}
});